#ifndef ATTR_AVE_H
#define ATTR_AVE_H
#include <vector>
#include <algorithm>
#include <iterator>
#include "attribute.h"
#include "attribute_info.h"

class attr_ave
{
public:
	//=======================================================
	// constructor and deconstructor
	//=======================================================
    attr_ave ()
    {
        _id = 0;
        _count = 0;
        _mean = 0;
        _type = ATTR_DISCRETE;
    }

    attr_ave (int id, vector < attribute_info > *infos)
    {
        init_map (id, infos);
        _count = 0;
        _mean = 0;
    }

//initialize the coef  struture to 0.
//make ready to count.
    int init_map (int id, vector < attribute_info > *infos)
    {
        _id = id;
        _type = infos->at (id).type ();//NOT STRONG!!!!!
        if (_type == ATTR_DISCRETE)
        {
            string item;
            for (int i = 0; i < infos->at (id)._range.size (); i++)
            {
                item = infos->at (id)._range.at (i);
                _discrete_attr_map.insert (std::make_pair (item, 0));
            }
        }
        else
        {
            _mean = 0;
        }
    }
	//=======================================================
	// Print
	//=======================================================

    friend ostream& operator<<(ostream& os, const attr_ave& atpr)
    {
        os<<"attribution: "<<atpr._id<<std::endl;
        if (atpr._type==ATTR_DISCRETE)
        {
            map<string,int>::const_iterator iter=atpr._discrete_attr_map.begin();
            while (iter!=atpr._discrete_attr_map.end())
            {
                os<<iter->first<<": "<<iter->second<<endl;
                iter++;
            }
        }
        else
        {
            os<<atpr._mean;
        }
        os<<endl<<endl;
    }
    //================================================
    //     MEMBER
    //================================================
    int _id;
    int _type;
    //for numeric attribution
    int _count;
    float _mean;
    //for discrete attribution
    map < string, int >     _discrete_attr_map;
};
#endif
